package com.yyks.es.dubbo.pojo.dto;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class HotelInfoC2bHotelVipSearchDto {

    @ApiModelProperty("酒店id")
    private String hotelId;
    @ApiModelProperty("距离")
    private Integer distance;
    @ApiModelProperty("维度")
    private String positionY;
    @ApiModelProperty("经度")
    private String positionX;
    @ApiModelProperty(value = "附加信息",hidden = true)
    @JsonIgnore
    private String extraInfo;
    @ApiModelProperty("酒店名称")
    private String hotelName;
    @ApiModelProperty("评分")
    private Integer score;
    @ApiModelProperty("舒适度")
    private Integer comfortLevel;
    @ApiModelProperty("电话")
    private String phone;
    @ApiModelProperty("电话")
    private String tel;
    @ApiModelProperty("星级")
    private Integer starLevel;
    @ApiModelProperty("星级")
    private String star;
    @ApiModelProperty("地址")
    private String address;
    @ApiModelProperty("房间展示信息")
    private List<HotelInfoC2bHotelVipSearchRoomDto> roomList;
    @ApiModelProperty("设施列表")
    private List<String> installation;

    @ApiModelProperty("图片")
    public String getImgUrl() {
        try {
            return JSONUtil.parseObj(extraInfo).getJSONArray("imgUrlList").toList(String.class).get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public String getStar() {
        switch (getStarLevel()) {
            case 2:
                return "民宿";
            case 3:
            case 4:
            case 5:
                return "星级";
            case 6:
                return "商务";
            default:
                return "";
        }
    }

    public void setRoomList(String roomList) {
        this.roomList = JSONUtil.toList(JSONUtil.parseArray(roomList), HotelInfoC2bHotelVipSearchRoomDto.class);
    }

    @ApiModelProperty("设施列表")
    public List<String> getInstallation() {
        try {
            return CollectionUtil.newArrayList(JSONUtil.parseObj(getExtraInfo()).getStr("devices").split(","));
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

}
